ADO: Jak ziskat result ze StoredProc
Otázka od: Karel Kral
8. 11. 2002 15:07
Prosim o pomoc (D7 Pro):
Jak ziskat navratovou hodnotu ze StoredProc (MSSQL2000), ktera se v ni
nastavuje pomoci Return(5001)?
Trapim se s tim cely den a zatim bez vysledku.
Zkousim to pomoci parametru pdReturnValue (to hlasi nespravny pocet
parametru), hledam ve zdrojakach po properties TADOCommand, zatim
bezvysledne.
Zde je StoredProc:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
/*************************************************************
testovaci procedura - vraci jen chyby
*************************************************************/
ALTER procedure [TestErr] (
@MessageText varchar (256) OUT,
@RaiseError bit
)
as
select @MessageText = 'OK'
if @RaiseError = 1
begin
select @MessageText = 'Chyba'
-- raiserror(50001, 16, 1, 'Parametr @RaiseError nastaven na 1')
return(50001)
end
else
return(0)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Zde je procedura:
// volano pred exportem, zalozi prechodnou tabulku
procedure TAbSqlCisExport.Open;
var
S: string;
Param: TParameter;
i: Integer;
Cmd: TADOCommand;
begin
S := 'Output parameters: '#13;
Cmd := TADOCommand.Create(nil);
with Cmd do
try
Connection := dmMain.connMain;
CommandType := cmdStoredProc;
CommandText := 'TestErr';
ExecuteOptions := ExecuteOptions + [eoExecuteNoRecords];
// napln parametry
with Parameters do
begin
CreateParameter('@MessageText', ftString, pdInputOutput, 25,
'Moje
hlášení');
CreateParameter('@RaiseError', ftBoolean, pdInput, 0, true);
// CreateParameter('Return', ftInteger, pdReturnValue, 0, 0);
end; // with
Execute;
with Parameters do
for i := 0 to Count - 1 do
begin
Param := Items[i];
S := S + Format('%s: %s', [Param.Name, VarToStr(Param.Value)]) +
#13;
end; // for
ShowMessage(S);
finally
Free;
end; // try/finally
end; // proc
--
______________________________________________________
Karel Kral, vedouci odd. IT / IT dep. manager
Purus, s.r.o., Cezavy 627, 664 56 Blucina, CZ
Tel: 547 235 000, 602 552 432, Fax: 547 231 203
E-Mail: mailto:kral@purus.cz, WWW: http://www.purus.cz
______________________________________________________
Odpovedá: Tom xXx
8. 11. 2002 15:15
No, zkus to treba takto:
with Parameters do
begin
Refresh;
ParamValues['@MessageText'] := 'Moje hlášení';
ParamValues['@RaiseError'] := True;
end; // with
Execute;
TenBlbejReturn := Parameters[0].Value;
T.